package ru.kruzhki.server.command;

import static com.googlecode.objectify.ObjectifyService.ofy;

import java.util.List;

import ru.kruzhki.shared.command.SearchCompanyRequest;
import ru.kruzhki.shared.command.SearchCompanyResponse;
import ru.kruzhki.shared.model.Company;

import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;


public class SearchCompanyActionHandler implements ActionHandler<SearchCompanyRequest, SearchCompanyResponse> {


	@Inject
	public SearchCompanyActionHandler() {
	}

	@Override
	public SearchCompanyResponse execute(SearchCompanyRequest request,	ExecutionContext context) throws ActionException {
		List<Company> result = ofy().load().type(Company.class).limit(50).offset(0).list();
		SearchCompanyResponse resonse=new SearchCompanyResponse();
		resonse.getItems().addAll(result);
		return resonse;
	}

	@Override
	public void undo(SearchCompanyRequest action, SearchCompanyResponse result, ExecutionContext context) throws ActionException {
		//
	}

	@Override
	public Class<SearchCompanyRequest> getActionType() {
		return SearchCompanyRequest.class;
	}
}
